/*
 * > /*
 >  * INSANE - Interactive Structural Analysis Environment
 >  *
 >  * Copyright (C) 2003-2004
 >  * Universidade Federal de Minas Gerais
 >  * Escola de Engenharia
 >  * Departamento de Engenharia de Estruturas
 >  *
 >  * Author's email :     insane@dees.ufmg.br
 >  * Author's Website :   http://www.dees.ufmg.br/insane
 >  *
 >  * This program is free software; you can redistribute it and/or
 >  * modify it under the terms of the GNU General Public License
 >  * as published by the Free Software Foundation; either version 2
 >  * of the License, or any later version.
 >  *
 >  * This program is distributed in the hope that it will be useful,
 >  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 >  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 >  * GNU General Public License for more details.
 >  *
 >  * You should have received a copy of the GNU General Public License
 >  * along with this program; if not, write to the Free Software
 >  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-
 > 1307, USA.
 *
 */
package br.ufmg.dees.insane.ui.rich.learn.learn_controller;


import java.awt.Graphics2D;
import java.awt.Point;
import java.util.ArrayList;
import java.util.ListIterator;

import br.ufmg.dees.insane.draw.Draw;
import br.ufmg.dees.insane.model.disc.fem.FemModel;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.IView;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.element_view.ElementView;


/**
 * 
 * @author Moreira, Renata & Pitangueira, Roque
 * @since August 2005
 */
public class GridModelSolutionController extends GridController {
	
    protected ArrayList<Draw> gaussMarks = new ArrayList<Draw>();
    
	public GridModelSolutionController(FemModel model) {
        this.model = model;
    }

    
    public GridModelSolutionController(FemModel model, IView eview) {
        this.model = model;
        this.view = eview;
    }

    
    public GridModelSolutionController(IView eview) {
        this.view = eview;
    }

    public GridModelSolutionController() {
    }
    
    public void setModel(FemModel newModel) {
        this.model = newModel;
    }

    public void setView(ElementView newView) {
        this.view = newView;
    }
    
    public void draw(Graphics2D g) {
        super.draw(g);
    }
    
    public void select(Point p) {
		Draw draw;
		int index;
		
		ListIterator lns = nodes.listIterator();
		while(lns.hasNext()) {
			draw = (Draw)lns.next();
			if (draw.contains(p)){
				if (draw.isSelected()) {
					draw.setSelected(false);
					index = selection.indexOf(draw.getRepresents());
					selection.remove(index);
					return;
				}else{
					draw.setSelected(true);
					selection.add(draw.getRepresents());
					return;
				}
			}
		}
		
		
	}
    
    public void selectAll() {
        Draw draw;
		selection.clear();
        
		ListIterator lns = nodes.listIterator();
		while(lns.hasNext()) {
			draw = (Draw)lns.next();
			draw.setSelected(true);
			selection.add(draw.getRepresents());
		}
		
	}
    
    public void unSelectAll() {
        Draw draw;
		selection.clear();
        
        ListIterator pts = nodes.listIterator();
        while(pts.hasNext()) {
            draw = (Draw)pts.next();
            draw.setSelected(false);
        }
		
	}
    
    public boolean isSelected() {
        Draw draw;

        ListIterator pts = nodes.listIterator();
        while (pts.hasNext()) {
            draw = (Draw) pts.next();
            if (draw.isSelected()) {
                return true;
            }
        }
        return false;
  }
    
    public void compose() {
        this.removeAll();
        super.compose();
        
	}	
        
    
        
        
}